package FirstStage.LingQianTong;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
// 零钱通菜单
public class SmallChangeSys {
    public static void main(String[] args) {
        Scanner scanner =new Scanner(System.in);
        boolean loop =true;
        String key="";
        String details = "----------零钱明细----------";
        double money=0;
        double banlance=0;
        Date date =null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //用于日期格式化
        String note="";
        do{
            System.out.println("\n==========零钱通菜单==========");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 零钱通入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退  出");
            System.out.println("请选择（1-4）: ");
            key = scanner.next();

            switch (key){
                case "1":
                    System.out.println(details);
                    break;
                case "2":
                    System.out.print("收益入账金额:");
                    money = scanner.nextDouble();
                    banlance +=money;
                    // 拼接收益入账信息到 details
                    date = new Date(); // 获取当前日期
                    details += "\n收益入账\t"+money+"\t"+sdf.format(date)+"\t"+banlance;
                    break;
                case "3":
                    System.out.print("消费说明:");
                    note = scanner.next();
                    System.out.println("消费金额:");
                    money = scanner.nextDouble();
                    banlance -=money;
                    // 拼接收益入账信息到 details
                    date = new Date(); // 获取当前日期
                    details += "\n"+note+"\t"+"-"+money+"\t"+sdf.format(date)+"\t"+banlance;
                    break;
                case "4":
                    String choice="";
                    while (true){
                        System.out.println("你确定要退出吗?y/n");
                        choice =scanner.next();
                        if(choice.equals("y") || choice.equals("n")){
                            break;
                        }
                    }
                    if(choice.equals("y")){
                        loop=false;
                    }
                    break;
                default:
                    System.out.println("选择有误，请重写选择");
            }
        }while (loop);
        System.out.println("----------退出了零钱通系统----------");

    }
}
